package com.jstyle.jclife.daoManager;


import android.util.Log;

import com.jstyle.jclife.dao.UserInfoDao;
import com.jstyle.jclife.model.UserInfo;
import com.jstyle.jclife.utils.DbManager;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

/**
 * Created by Administrator on 2017/4/10.
 */

public class UserInfoDaoManager {

    /**插入数据，存在就更新，不存在插入；insertOrReplace适合手动添加id
     * save是判断id是否存在，适合有设置自增长id的实体
     * @param userInfo
     * @param
     */
    public static void insertUser(UserInfo userInfo){
        DbManager.getInstance().getDaoSession().getUserInfoDao().insert(userInfo);
    }
    public static void updateUser(UserInfo userInfo){
        DbManager.getInstance().getDaoSession().getUserInfoDao().update(userInfo);
    }

    private static final String TAG = "UserInfoDaoManager";
    public static UserInfo getUser(String phone){
        UserInfoDao userInfoDao=DbManager.getInstance().getDaoSession().getUserInfoDao();
        QueryBuilder<UserInfo> builder = userInfoDao.queryBuilder();
        builder.where(UserInfoDao.Properties.Phone.eq(phone));
        List<UserInfo>list=builder.list();
        Log.i(TAG, "getUser: ");
        return builder.unique();
    }
    public static UserInfo getUserByUid(String uid){
        UserInfoDao userInfoDao=DbManager.getInstance().getDaoSession().getUserInfoDao();
        QueryBuilder<UserInfo> builder = userInfoDao.queryBuilder();
        builder.where(UserInfoDao.Properties.UserId.eq(uid));
        return builder.unique();
    }
    public static List<UserInfo> getUser(){
        UserInfoDao userInfoDao=DbManager.getInstance().getDaoSession().getUserInfoDao();
        QueryBuilder<UserInfo> builder = userInfoDao.queryBuilder();
        return builder.list();
    }

}
